/**
 * @file name HallActivity.java
 */
package com.digital.community;

import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.EditText;

import com.digital.community.common.utils.StringUtils;
import com.digital.community.common.utils.ToastUtils;

/**
 * 
 * @author yarine.gao
 * @date 2012-11-3
 * @version 1.0.0
 */
public class IPSetActivity extends Activity {
    
	EditText ipET = null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ip);
        
        ipET = (EditText)findViewById(R.id.et_ip);
        
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
        String ip = sp.getString("ipEXC", "");
        ipET.setText(ip);
    }

    public void toSet(View view) {
    	
    	String ip = ipET.getText().toString().trim();
    	if(StringUtils.isBlank(ip)) {
    		ToastUtils.showErrorToast(this, getLayoutInflater(), "ip不能为空", false);
    		return;
    	}
    	String[] ipArr = ip.split("\\.");
    	if(ipArr.length != 4) {
    		ToastUtils.showErrorToast(this, getLayoutInflater(), "ip格式不对!", false);
    		return;
    	}
    	for(int i = 0; i < 4; i ++) {
    		if(!StringUtils.isNumeric(ipArr[i])) {
    			ToastUtils.showErrorToast(this, getLayoutInflater(), "ip格式不对!", false);
        		return;
    		}
    	}
    	
    	Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
    	editor.putString("ip", "http://" + ip + ":9999/SZSQGLXT/");
    	editor.putString("ipEXC", ip);
    	editor.commit();
    	
    	ToastUtils.showTrueToast(this, getLayoutInflater(), "ip设置成功!", false);
    }
}
